<template>
    <h1>病房列表</h1>
    病房名称:
    <input type="text" v-model="bname"/>
    所属科室:
    <select v-model="kid">
        <option value="-1">--请选择--</option>
        <option v-for="item in bang" :value="item.kId">{{ item.kName }}</option>
    </select>
    <input type="button" value="查询" @click="Show"/>

    <table class="table" border="1">
        <thead>
            <tr>
                <td>病房名称</td>
                <td>所属科室</td>
                <td>床位数</td>
                <td>状态</td>
                <td>空床数</td>
                <td>病房创建时间</td>
                <td>病房更新时间</td>
                <td>操作</td>
            </tr>
        </thead>
        <tbody>
            <tr v-for="item in Info">
                <td>{{item.bName}}</td>
                <td>{{item.kName}}</td>
                <td>{{item.bedSum}}床</td>
                <td>{{item.state==true?"启用":"维修"}}</td>
                <td>{{item.koBedSum}}床</td>
                <td>{{item.craDate.substring(0,10)}}</td>
                <td>{{item.gengDate.substring(0,10)}}</td>
                <td>
                    <input type="button" value="修改状态" @click="Upd(item.bId)"/>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref,onMounted } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
onMounted(()=>{
    Show();
    bing();
})
onMounted(()=>{
    bing();
})

const bang = ref([{
    "kId": 0,
  "kName": "",
}])

const bing=()=>{
    axios.get("https://localhost:7199/api/BingRoom/GetKeAll")
    .then(res=>{
        bang.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}

const Info=ref([{
    "bId": 0,
    "bName": "",
    "kId": 0,
    "bedSum": "",
    "state": true,
    "koBedSum": "0",
    "craDate": "",
    "gengDate": "",
    "kName": ""
}])

const bname=ref("")
const kid=ref(-1)

const Show=()=>{
    axios.get("https://localhost:7199/api/BingRoom/GetAll",{
        params:{
            bname:bname.value,
            kid:kid.value
        }
    })
    .then(res=>{
        Info.value=res.data
    })
    .catch(error=>{
        console.log(error);
    })
}

const Upd=(bId:number)=>{
    if(confirm("确定修改吗？")){
        axios.delete("https://localhost:7199/api/BingRoom/UpdByState",{
        params:{
            bid:bId
        }
    })
    .then(res=>{
        if(res.data>0){
            alert("修改成功！")
            Show();
        }
        else{
            alert("修改失败")
        }
    })
    .catch(error=>{
        console.log(error);
    })
    }
}

</script>